Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

125
Vistas
CucumberJS - how to use world object "this" outside of the given, when and then architecture

I was working on cucumber testing and met the issue that I don't know how to get the world object "this" outside of cucumber architecture

For example,

function verifyFunction(){
  expect(this.a).toEqual(1);
}


Given(
  /^bla bla bla$/, function () {
    this.a = 1
  }
);

Then(
  /^bla bla bla$/, function () {
    verifyFunction()
  }
);

When running the example test like above, it will show the error Cannot read property 'a' of undefined.

Any idea about how to solve this issue?

Thanks a lot!

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

try using ES6 syntax :

const verifyFunction = () =>{
 expect(this.a).toEqual(1);
} 
about 4 years ago · Juan Pablo Isaza Denunciar

0

Caveat: I only use Cucumber with ruby.

Generally when using functions from step refs you should pass things into the function and retrieve things from the function. In ruby you would share between steps using a global. So

module StepHelpers
  def get_foo
    return 'foo'
  end

  def bar(x)
    puts x
  end
end
World StepHelpers

Given 'foo' do
  @foo = get_foo
end

When 'bar with foo' do
  # We can access @foo because its defined as a global in a step
  bar(@foo)
end

Try translating the above into your js cukes

n.b. the module stuff is to prevent the methods getting into your applications global namespace.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda